package global

import (
	"bloggerService/etcdService"
	"flag"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/resolver"
)

var (
	// RPCConn Shared gRPC connection
	RPCConn     *grpc.ClientConn
	ServiceName = flag.String("ServiceName", "blogger_service", "服务名称")
	EtcdAddr    = flag.String("EtcdAddr", "127.0.0.1:2379", "注册地址")
)

func init() {
	fmt.Println("连接了")
	flag.Parse()
	r := etcdService.NewResolver(*EtcdAddr)
	resolver.Register(r)

	// 客户端连接服务器
	var err error
	RPCConn, err = grpc.Dial(r.Scheme()+"://author/"+*ServiceName, grpc.WithBalancerName("round_robin"), grpc.WithInsecure())
	if err != nil {
		fmt.Println("连接服务器失败", err)
	}
}
